#!/user/bin/python
# -*- coding: utf-8 -*-
'''
 @Time    : 2018/5/5 8:16
 @File    : socketio_msg.py
 @desc    :
'''


class MsgStatus(object):

    NONE = -999
    SUCCESS = 200
    FAILURE = -1

    @classmethod
    def is_success(cls, status):
        return status == cls.SUCCESS

    @classmethod
    def is_failure(cls, status):
        return status == cls.FAILURE


class Msg(dict):

    def __init__(self, **kwargs):
        self.update({
            'status': MsgStatus.NONE,
            'data': None,
            'msg': '',
            'error': ''
        })
        dict.__init__(self, **kwargs)

    def to_dict(self):
        return self


class Failure(Msg):

    def __init__(self, error):
        super(Failure, self).__init__(msg=error)
        self.update({
            'status': MsgStatus.FAILURE
        })


class Success(Msg):

    def __init__(self, msg='', data=''):
        super(Success, self).__init__(msg=msg, data=data)
        self.update({
            'status': MsgStatus.SUCCESS
        })


